package com.lagou.controller;

import com.lagou.feign.EmailFeignClient;
import com.lagou.service.CodeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.ParseException;
import java.util.Random;

@Controller
@Slf4j
@RequestMapping("/api")
public class CodeController {
    
    @Autowired
    CodeService service;

    @RequestMapping("/code/create/{email}")
    @ResponseBody
    public boolean createCode(@PathVariable String email) throws InterruptedException {
        log.info("开始创建验证码");
        Thread.sleep(5000);
        return service.createCode(email);
    }

    @RequestMapping("/code/validate/{email}/{code} ")
    @ResponseBody
    public int codeValidate(@PathVariable("email") String email, @PathVariable("code") String code) throws ParseException {
        return service.codeValidate(email, code);
    }

    @RequestMapping("/code/test")
    @ResponseBody
    public String testr(){
        log.info("开始创建验证码");
        return "test";
    }

}
